<template>
	<view>
		<list>
			<header>
				<text style="margin-left: 30rpx; line-height: 2.0em; font-weight: bold;">{{userinfo.name}}</text>
			</header>
			<cell>
				<text style="margin-left: 30rpx; margin-top: 60rpx;">已预约</text>
			</cell>
			<cell v-for="hotel in hotels" @click="clickHotel(hotel)">
				<find_hotel :hotel_data=hotel.hotelinfo></find_hotel>
			</cell>
		</list>
	</view>
</template>

<script>
	import find_hotel from '../../components/find_hotel.vue';
	import config from '../../common/config.js';
	
	export default {
		data() {
			return {
				"hotels": [],
				"userinfo":{}
			}
		},
		methods: {
			hotelRequest() {
				uni.request({
					url: config.hosts+'hotel/myreservation',
					method: 'POST',
					header:{
						'content-type': 'application/json'
					},
					data: {
						userid: this.userinfo.uid
					},
					success: res => {
						this.hotels = res.data;
						console.log(res.data);
					},
					fail: () => {
						console.log("失败");
					},
					complete: () => {
					}
				});
			},
			clickHotel(e) {
				var data = JSON.stringify(e);
				uni.navigateTo({
					url: '../hotelinfo/reservationHotelinfo?data='+data,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad() {
		},
		onShow() {
			try {
				const value = uni.getStorageSync('userinfo');
				if (value) {
					this.userinfo = JSON.parse(value);
				}
			} catch (e) {
				// error
			}
			this.hotelRequest();
		},
		components: {
			find_hotel
		}
	}
</script>

<style>

</style>
